<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>logicmatcher.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_labs_testing_logicmatcher.js.html">logicmatcher.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Provides the built-in logic matchers: anyOf, allOf, and isNot.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.labs.testing.AllOfMatcher&#39;);
<a name="line22"></a>goog.provide(&#39;goog.labs.testing.AnyOfMatcher&#39;);
<a name="line23"></a>goog.provide(&#39;goog.labs.testing.IsNotMatcher&#39;);
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>goog.require(&#39;goog.array&#39;);
<a name="line27"></a>goog.require(&#39;goog.labs.testing.Matcher&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>/**
<a name="line32"></a> * The AllOf matcher.
<a name="line33"></a> *
<a name="line34"></a> * @param {!Array.&lt;!goog.labs.testing.Matcher&gt;} matchers Input matchers.
<a name="line35"></a> *
<a name="line36"></a> * @constructor
<a name="line37"></a> * @implements {goog.labs.testing.Matcher}
<a name="line38"></a> */
<a name="line39"></a>goog.labs.testing.AllOfMatcher = function(matchers) {
<a name="line40"></a>  /**
<a name="line41"></a>   * @type {!Array.&lt;!goog.labs.testing.Matcher&gt;}
<a name="line42"></a>   * @private
<a name="line43"></a>   */
<a name="line44"></a>  this.matchers_ = matchers;
<a name="line45"></a>};
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * Determines if all of the matchers match the input value.
<a name="line50"></a> *
<a name="line51"></a> * @override
<a name="line52"></a> */
<a name="line53"></a>goog.labs.testing.AllOfMatcher.prototype.matches = function(actualValue) {
<a name="line54"></a>  return goog.array.every(this.matchers_, function(matcher) {
<a name="line55"></a>    return matcher.matches(actualValue);
<a name="line56"></a>  });
<a name="line57"></a>};
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>/**
<a name="line61"></a> * Describes why the matcher failed. The returned string is a concatenation of
<a name="line62"></a> * all the failed matchers&#39; error strings.
<a name="line63"></a> *
<a name="line64"></a> * @override
<a name="line65"></a> */
<a name="line66"></a>goog.labs.testing.AllOfMatcher.prototype.describe =
<a name="line67"></a>    function(actualValue) {
<a name="line68"></a>  // TODO(user) : Optimize this to remove duplication with matches ?
<a name="line69"></a>  var errorString = &#39;&#39;;
<a name="line70"></a>  goog.array.forEach(this.matchers_, function(matcher) {
<a name="line71"></a>    if (!matcher.matches(actualValue)) {
<a name="line72"></a>      errorString += matcher.describe(actualValue) + &#39;\n&#39;;
<a name="line73"></a>    }
<a name="line74"></a>  });
<a name="line75"></a>  return errorString;
<a name="line76"></a>};
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>
<a name="line80"></a>/**
<a name="line81"></a> * The AnyOf matcher.
<a name="line82"></a> *
<a name="line83"></a> * @param {!Array.&lt;!goog.labs.testing.Matcher&gt;} matchers Input matchers.
<a name="line84"></a> *
<a name="line85"></a> * @constructor
<a name="line86"></a> * @implements {goog.labs.testing.Matcher}
<a name="line87"></a> */
<a name="line88"></a>goog.labs.testing.AnyOfMatcher = function(matchers) {
<a name="line89"></a>  /**
<a name="line90"></a>   * @type {!Array.&lt;!goog.labs.testing.Matcher&gt;}
<a name="line91"></a>   * @private
<a name="line92"></a>   */
<a name="line93"></a>  this.matchers_ = matchers;
<a name="line94"></a>};
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/**
<a name="line98"></a> * Determines if any of the matchers matches the input value.
<a name="line99"></a> *
<a name="line100"></a> * @override
<a name="line101"></a> */
<a name="line102"></a>goog.labs.testing.AnyOfMatcher.prototype.matches = function(actualValue) {
<a name="line103"></a>  return goog.array.some(this.matchers_, function(matcher) {
<a name="line104"></a>    return matcher.matches(actualValue);
<a name="line105"></a>  });
<a name="line106"></a>};
<a name="line107"></a>
<a name="line108"></a>
<a name="line109"></a>/**
<a name="line110"></a> * Describes why the matcher failed.
<a name="line111"></a> *
<a name="line112"></a> * @override
<a name="line113"></a> */
<a name="line114"></a>goog.labs.testing.AnyOfMatcher.prototype.describe =
<a name="line115"></a>    function(actualValue) {
<a name="line116"></a>  // TODO(user) : Optimize this to remove duplication with matches ?
<a name="line117"></a>  var errorString = &#39;&#39;;
<a name="line118"></a>  goog.array.forEach(this.matchers_, function(matcher) {
<a name="line119"></a>    if (!matcher.matches(actualValue)) {
<a name="line120"></a>      errorString += matcher.describe(actualValue) + &#39;\n&#39;;
<a name="line121"></a>    }
<a name="line122"></a>  });
<a name="line123"></a>  return errorString;
<a name="line124"></a>};
<a name="line125"></a>
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * The IsNot matcher.
<a name="line130"></a> *
<a name="line131"></a> * @param {!goog.labs.testing.Matcher} matcher The matcher to negate.
<a name="line132"></a> *
<a name="line133"></a> * @constructor
<a name="line134"></a> * @implements {goog.labs.testing.Matcher}
<a name="line135"></a> */
<a name="line136"></a>goog.labs.testing.IsNotMatcher = function(matcher) {
<a name="line137"></a>  /**
<a name="line138"></a>   * @type {!goog.labs.testing.Matcher}
<a name="line139"></a>   * @private
<a name="line140"></a>   */
<a name="line141"></a>  this.matcher_ = matcher;
<a name="line142"></a>};
<a name="line143"></a>
<a name="line144"></a>
<a name="line145"></a>/**
<a name="line146"></a> * Determines if the input value doesn&#39;t satisfy a matcher.
<a name="line147"></a> *
<a name="line148"></a> * @override
<a name="line149"></a> */
<a name="line150"></a>goog.labs.testing.IsNotMatcher.prototype.matches = function(actualValue) {
<a name="line151"></a>  return !this.matcher_.matches(actualValue);
<a name="line152"></a>};
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Describes why the matcher failed.
<a name="line157"></a> *
<a name="line158"></a> * @override
<a name="line159"></a> */
<a name="line160"></a>goog.labs.testing.IsNotMatcher.prototype.describe =
<a name="line161"></a>    function(actualValue) {
<a name="line162"></a>  return &#39;The following is false: &#39; + this.matcher_.describe(actualValue);
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * Creates a matcher that will succeed only if all of the given matchers
<a name="line168"></a> * succeed.
<a name="line169"></a> *
<a name="line170"></a> * @param {...goog.labs.testing.Matcher} var_args The matchers to test
<a name="line171"></a> *     against.
<a name="line172"></a> *
<a name="line173"></a> * @return {!goog.labs.testing.AllOfMatcher} The AllOf matcher.
<a name="line174"></a> */
<a name="line175"></a>function allOf(var_args) {
<a name="line176"></a>  var matchers = goog.array.toArray(arguments);
<a name="line177"></a>  return new goog.labs.testing.AllOfMatcher(matchers);
<a name="line178"></a>}
<a name="line179"></a>
<a name="line180"></a>
<a name="line181"></a>/**
<a name="line182"></a> * Accepts a set of matchers and returns a matcher which matches
<a name="line183"></a> * values which satisfy the constraints of any of the given matchers.
<a name="line184"></a> *
<a name="line185"></a> * @param {...goog.labs.testing.Matcher} var_args The matchers to test
<a name="line186"></a> *     against.
<a name="line187"></a> *
<a name="line188"></a> * @return {!goog.labs.testing.AnyOfMatcher} The AnyOf matcher.
<a name="line189"></a> */
<a name="line190"></a>function anyOf(var_args) {
<a name="line191"></a>  var matchers = goog.array.toArray(arguments);
<a name="line192"></a>  return new goog.labs.testing.AnyOfMatcher(matchers);
<a name="line193"></a>}
<a name="line194"></a>
<a name="line195"></a>
<a name="line196"></a>/**
<a name="line197"></a> * Returns a matcher that negates the input matcher. The returned
<a name="line198"></a> * matcher matches the values not matched by the input matcher and vice-versa.
<a name="line199"></a> *
<a name="line200"></a> * @param {!goog.labs.testing.Matcher} matcher The matcher to test against.
<a name="line201"></a> *
<a name="line202"></a> * @return {!goog.labs.testing.IsNotMatcher} The IsNot matcher.
<a name="line203"></a> */
<a name="line204"></a>function isNot(matcher) {
<a name="line205"></a>  return new goog.labs.testing.IsNotMatcher(matcher);
<a name="line206"></a>}
</pre>


</body>
</html>
